<?php

/**
 * @name: HOTN AnimeList
 * @author: HammerOnTheNail
 * @link: http://code.google.com/p/hotnanimelist/
 */

// Alap dolgok bekérése
include("../../class2.php");
include(e_PLUGIN."/hotn_animelist/Languages/".e_LANGUAGE.".php");
include(e_PLUGIN."hotn_animelist/Class/animelist_mysql.php");

// hotn_animelist css file beolvasása
if (file_exists(THEME."hotn_animelist/animelist.css")) $eplug_css[] = THEME."hotn_animelist/animelist.css";
else $eplug_css[] = e_PLUGIN_ABS."hotn_animelist/Class/animelist.css";
	

// Munkák kiválogatása
function show_work($team_id)
{
	global $sql;
	
	$sql->db_Select(
	"hotn_animelist_project as project, ".MPREFIX."hotn_animelist_team as team",
	"`project_id`,`project_name`","
		team_id = ".$team_id." and
		(
		project_team_leader = team_id or
		 
		project_translator REGEXP('%{$team_id}$') or
		project_translator REGEXP('%{$team_id}%') or
		project_translator REGEXP('^{$team_id}%') or
		project_translator = '{$team_id}' or
		
		project_karaoke REGEXP('%{$team_id}$') or
		project_karaoke REGEXP('%{$team_id}%') or
		project_karaoke REGEXP('^{$team_id}%') or
		project_karaoke = '{$team_id}' or
		
		project_format REGEXP('%{$team_id}$') or
		project_format REGEXP('%{$team_id}%') or
		project_format REGEXP('^{$team_id}%') or
		project_format = '{$team_id}' or
		
		project_video REGEXP('%{$team_id}$') or
		project_video REGEXP('%{$team_id}%') or
		project_video REGEXP('^{$team_id}%') or
		project_video = '{$team_id}' or
		
		project_lector REGEXP('%{$team_id}$') or
		project_lector REGEXP('%{$team_id}%') or
		project_lector REGEXP('^{$team_id}%') or
		project_lector = '{$team_id}' or
		
		project_manga_format REGEXP('%{$team_id}$') or
		project_manga_format REGEXP('%{$team_id}%') or
		project_manga_format REGEXP('^{$team_id}%') or
		project_manga_format = '{$team_id}' or
		
		project_timer REGEXP('%{$team_id}$') or
		project_timer REGEXP('%{$team_id}%') or
		project_timer REGEXP('^{$team_id}%') or
		project_timer = '{$team_id}'
		)
		
		GROUP BY project_id ORDER BY project_type ASC, project_name ASC",
	"default",false);
	while ($row = $sql->db_Fetch())
	{
		$text .= "<li><a href='project_download.php?".$row['project_id']."'>".$row['project_name']."</a></li>";
	}
	
	if ($text <> "" )
	{
		$text = "
		<tr>
			<td class='hotn_animelist_team_project_caption'>
				".HOTN_ANIMELIST_TEAM_PROJECT."
			</td>
			<td class='hotn_animelist_team_project'>
				<ul >".$text."</ul>
			</td>
		</tr>
		";
	}
	return $text;
}

if (!is_numeric(e_QUERY))
{
	
	// Oldal címe
	define("e_PAGETITLE",HOTN_ANIMELIST_TEAM_TITLE);
	$title = HOTN_ANIMELIST_TEAM_TITLE;
	
	// Adatok lekérése
	$sql->db_Select("hotn_animelist_team, ".MPREFIX."user", "*", "user_id = team_id ORDER BY user_name ASC");
	$text_team .= "<table class='hotn_animelist_team'>";
	while ($user_row = $sql->db_Fetch())
	{
		// Felhasználó avatárjának vizsgálata
		if($user_row['user_image'] == "")
		{
			if ( file_exists(THEME."hotn_animelist/images/default_avatar.png") )
				$user_image = THEME."hotn_animelist/images/default_avatar.png";
			else
				$user_image = e_PLUGIN."hotn_animelist/Images/default_avatar.png";
		}
		else
		{
			require_once(e_HANDLER."avatar_handler.php");
			$user_image = avatar($user_row['user_image']);
		}
		$user_image = "<img src='".$user_image."' alt='' />";
		
		$text_team .= "
			<tr class='hotn_animelist_team_row'>
				<td class='hotn_animelist_team_avatar'>
					<a href='project_team.php?".$user_row['user_id']."'>".$user_image."</a>
				</td>
				<td class='hotn_animelist_team_more'>
					<table>
						<tr>
							<td class='hotn_animelist_team_username_caption'>
								".HOTN_ANIMELIST_TEAM_USERNAME."
							</td>
							<td class='hotn_animelist_team_username'>
								<a href='project_team.php?".$user_row['user_id']."'>".$user_row['user_name']."</a>
							</td>
						</tr>
						<tr>
							<td class='hotn_animelist_team_do_caption'>
								".HOTN_ANIMELIST_TEAM_DO."
							</td>
							<td class='hotn_animelist_team_do'>
								".$user_row['team_do']."
							</td>
						</tr>
					</table>
				</td>
			</tr>
			";
	}
	$text_team .= "</table>";
}
else
{
	// adatok lekérése
	$id = (int)e_QUERY;
	$sql->db_Select("hotn_animelist_team, ".MPREFIX."user", "*", "user_id = ".$id." and team_id = ".$id);
	$user_row = $sql->db_Fetch();
	
	if (!$user_row) header("Location: project_team.php");
	
	// Oldal címe
	define("e_PAGETITLE",HOTN_ANIMELIST_TEAM_TITLE.": ".$user_row['user_name']);
	$title = HOTN_ANIMELIST_TEAM_TITLE.": ".$user_row['user_name'];
	
	// User kép
	$user_image = "";
	if($user_row['user_sess'] <> "")
	{
		$user_image = e_FILE."public/avatars/".$user_row['user_sess'];
		if (!is_file($user_image)) $user_image = "";
	}
	
	if ($user_image == "")
	{
		if ( file_exists(THEME."hotn_animelist/images/default_image.png") )
			$user_image = THEME."hotn_animelist/images/default_image.png";
		else
			$user_image = e_PLUGIN."hotn_animelist/Images/default_image.png";
	}
	$user_image = "<img src='".$user_image."' alt='' />";
	
	if ( file_exists(THEME."hotn_animelist/images/profil.png") )
	{
		$profil_image = THEME."hotn_animelist/images/profil.png";
	}
	else
	{
		$profil_image = e_PLUGIN."hotn_animelist/Images/profil.png";
	}
	$profil_image = "<img src='".$profil_image."' alt='' />";
	
	$text_team .= "
		<table class='hont_animelist_team_content'>
			<tr>
				<td class='hont_animelist_team_image'>
					".$user_image."
				</td>
				<td class='hont_animelist_team_text'>
					<table>
						<tr>
							<td class='hont_animelist_team_username_caption'>
								".HOTN_ANIMELIST_TEAM_USERNAME."
							</td>
							<td class='hont_animelist_team_username'>
								".$user_row['user_name']." <a href=".e_BASE."user.php?id.".$id.">".$profil_image."</a>
							</td>
						</tr>
						<tr>
							<td class='hotn_animelist_team_do_caption'>
								".HOTN_ANIMELIST_TEAM_DO."
							</td>
							<td class='hotn_animelist_team_do'>
								".$user_row['team_do']."
							</td>
						</tr>
						<tr>
							<td class='hotn_animelist_team_email_caption'>
								".HOTN_ANIMELIST_TEAM_EMAIL."
							</td>
							<td class='hotn_animelist_team_email'>
								<a href='mailto:".$user_row['user_email']."'>".$user_row['user_email']."</a>
							</td>
						</tr>
						".show_work($user_row['team_id'])."
					</table>
				</td>
			</tr>
		</table>
	";
}

// Oldal megjelenítése
require_once(HEADERF);
$ns -> tablerender($title, $text_team, "");
require_once(FOOTERF);
?>